From fa58d9e8fe9a810916eb8e627dc5adde3f995ef0 Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 12 Aug 2006 21:53:24 +0000 Subject: [PATCH] Add --with-zlib as a tristate for our zlib, system zlib, or no zlib. --- Makefile.in | 2 +- config.h.in | 8 +++- configure | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++- configure.in | 15 +++++++- gbfile.c | 55 ++++++++++++++++++++++++++- 5 files changed, 178 insertions(+), 6 deletions(-) diff --git a/Makefile.in b/Makefile.in index 69ef8b60e..839cf4af3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,7 +84,7 @@ LIBOBJS = queue.o route.o waypt.o filter_vecs.o util.o vecs.o mkshort.o \ uuid.o formspec.o xmltag.o cet.o cet_util.o fatal.o rgbcolors.o \ inifile.o garmin_fs.o gbsleep.o units.o textfile.o @GBSER@ gbser.o \ gbfile.o \ - $(COLDSYNC) $(GARMIN) $(JEEPS) $(SHAPE) $(ZLIB) $(FMTS) $(FILTERS) + $(COLDSYNC) $(GARMIN) $(JEEPS) $(SHAPE) @ZLIB@ $(FMTS) $(FILTERS) OBJS = main.o globals.o $(LIBOBJS) @FILEINFO@ .c.o: diff --git a/config.h.in b/config.h.in index 5923858d6..1bd4136c8 100644 --- a/config.h.in +++ b/config.h.in @@ -18,6 +18,9 @@ /* Defined if you have libusb */ #undef HAVE_LIBUSB +/* Define to 1 if you have the `z' library (-lz). */ +#undef HAVE_LIBZ + /* Define to 1 if you have the `nanosleep' function. */ #undef HAVE_NANOSLEEP @@ -30,7 +33,7 @@ /* Define to the full name of this package. */ #undef PACKAGE_NAME -/* Define to the release of this package. */ +/* Define to the release name of this package. */ #undef PACKAGE_RELEASE /* Define to the full name and version of this package. */ @@ -47,3 +50,6 @@ /* 1 to enable shapefile support */ #undef SHAPELIB_ENABLED + +/* 1 to inhibit our use of zlib. */ +#undef ZLIB_INHIBITED diff --git a/configure b/configure index 2f42ef36b..bf075830c 100755 --- a/configure +++ b/configure @@ -273,7 +273,7 @@ PACKAGE_VERSION='1.3.0' PACKAGE_STRING='GPSBabel 1.3.0' PACKAGE_BUGREPORT='BUG-REPORT-ADDRESS' -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE_RELEASE GBMAJOR GBMINOR GBMICRO build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA SET_MAKE FILEINFO RC LIBUSBCONFIG USB_LIBS USB_CFLAGS OSJEEPS GBSER EXPAT_LIB LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE_RELEASE GBMAJOR GBMINOR GBMICRO build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA SET_MAKE FILEINFO RC LIBUSBCONFIG USB_LIBS USB_CFLAGS OSJEEPS GBSER ZLIB EXPAT_LIB LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -816,6 +816,7 @@ Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-cet=(default,all,minimal) + --with-zlib=(included)|system|no --with-expathdr=DIR Use this to specify the location of expat.h --with-libexpat=DIR Use this to specify expat library . @@ -2640,6 +2641,104 @@ echo "${ECHO_T}yes" >&6 echo "${ECHO_T}no" >&6 fi +echo "$as_me:$LINENO: checking whether to support zlib" >&5 +echo $ECHO_N "checking whether to support zlib... $ECHO_C" >&6 + +# Check whether --with-zlib or --without-zlib was given. +if test "${with_zlib+set}" = set; then + withval="$with_zlib" + +fi; + case $with_zlib in + "system") + +echo "$as_me:$LINENO: checking for gzopen in -lz" >&5 +echo $ECHO_N "checking for gzopen in -lz... $ECHO_C" >&6 +if test "${ac_cv_lib_z_gzopen+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lz $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char gzopen (); +int +main () +{ +gzopen (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_z_gzopen=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_z_gzopen=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_z_gzopen" >&5 +echo "${ECHO_T}$ac_cv_lib_z_gzopen" >&6 +if test $ac_cv_lib_z_gzopen = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBZ 1 +_ACEOF + + LIBS="-lz $LIBS" + +fi + + ;; + "no") + +cat >>confdefs.h <<\_ACEOF +#define ZLIB_INHIBITED 1 +_ACEOF + + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + ;; + *) ZLIB="\$(ZLIB)" + echo "$as_me:$LINENO: result: using included version" >&5 +echo "${ECHO_T}using included version" >&6;; + esac case "$target" in *-*-mingw32*) @@ -2821,6 +2920,7 @@ esac + echo "$as_me:$LINENO: checking for random stuff to make you feel better" >&5 echo $ECHO_N "checking for random stuff to make you feel better... $ECHO_C" >&6 echo "$as_me:$LINENO: result: failed" >&5 @@ -2957,7 +3057,6 @@ _ACEOF fi -echo $EXPAT_LIB # Checks for header files. # AC_HEADER_STDC @@ -3735,6 +3834,7 @@ s,@USB_LIBS@,$USB_LIBS,;t t s,@USB_CFLAGS@,$USB_CFLAGS,;t t s,@OSJEEPS@,$OSJEEPS,;t t s,@GBSER@,$GBSER,;t t +s,@ZLIB@,$ZLIB,;t t s,@EXPAT_LIB@,$EXPAT_LIB,;t t s,@LIBOBJS@,$LIBOBJS,;t t s,@LTLIBOBJS@,$LTLIBOBJS,;t t diff --git a/configure.in b/configure.in index 558946f6b..1ead1b09d 100644 --- a/configure.in +++ b/configure.in @@ -92,6 +92,19 @@ AC_ARG_ENABLE(filters, AC_MSG_RESULT(no) fi +AC_MSG_CHECKING(whether to support zlib) +AC_ARG_WITH(zlib, [ --with-zlib=[(included)|system|no]]) + case $with_zlib in + "system") + AC_CHECK_LIB([z], [gzopen]) + ;; + "no") + AC_DEFINE(ZLIB_INHIBITED, 1, [1 to inhibit our use of zlib.]) + AC_MSG_RESULT(no) + ;; + *) ZLIB="\$(ZLIB)" + AC_MSG_RESULT(using included version);; + esac case "$target" in *-*-mingw32*) @@ -164,6 +177,7 @@ AC_SUBST(USB_LIBS) AC_SUBST(USB_CFLAGS) AC_SUBST(OSJEEPS) AC_SUBST(GBSER) +AC_SUBST(ZLIB) AC_MSG_CHECKING(for random stuff to make you feel better) AC_MSG_RESULT(failed) @@ -213,7 +227,6 @@ AC_CHECK_LIB([expat], [XML_ParserCreate], AC_SUBST(EXPAT_LIB) # [EXPAT_LIB="$LDFLAGS -lexpat"] ) -echo $EXPAT_LIB # Checks for header files. # AC_HEADER_STDC diff --git a/gbfile.c b/gbfile.c index bbca7a24e..f78ce5f3d 100644 --- a/gbfile.c +++ b/gbfile.c @@ -31,6 +31,14 @@ #define MYNAME "gbfile" +/* About the ZLIB_INHIBITED stuff: + * + * If a user goes out of his way to build with ZLIB_INHIBITED set, + * we jettison our use of zlib entirely within this file, replacing + * all calls out to zlib with calls to abort() as that's an internal + * consistency error. + * + */ /* GPSBabel 'file' standard calls */ @@ -69,6 +77,7 @@ gbfopen(const char *filename, const char *mode, const char *module) } if (file->gzapi) { +#if !ZLIB_INHIBITED file->handle.gz = gzopen(filename, mode); if (file->handle.gz == NULL) { fatal("%s: Cannot %s file '%s'!\n", @@ -77,6 +86,10 @@ gbfopen(const char *filename, const char *mode, const char *module) filename); } file->gzapi = 1; +#else + /* This is the only runtime test we make */ + fatal("Zlib was not included in this build."); +#endif } else { file->handle.std = xfopen(filename, mode, module); @@ -112,7 +125,11 @@ gbfclose(gbfile *file) if (!file) return; if (file->gzapi) { +#if !ZLIB_INHIBITED gzclose(file->handle.gz); +#else + abort(); +#endif } else { fclose(file->handle.std); @@ -170,7 +187,12 @@ gbfread(void *buf, const gbsize_t size, const gbsize_t members, gbfile *file) if ((size == 0) || (members == 0)) return 0; if (file->gzapi) { - int result = gzread(file->handle.gz, buf, size * members) / size; + int result; +#if !ZLIB_INHIBITED + result = gzread(file->handle.gz, buf, size * members) / size; +#else + abort(); +#endif if ((result < 0) || ((gbsize_t)result < members)) { int errnum; const char *errtxt; @@ -246,7 +268,11 @@ gbfwrite(const void *buf, const gbsize_t size, const gbsize_t members, gbfile *f if ((size == 0) || (members == 0)) return 0; if (file->gzapi) { +#if !ZLIB_INHIBITED result = gzwrite(file->handle.gz, buf, size * members) / size; +#else + abort(); +#endif } else { result = fwrite(buf, size, members, file->handle.std); @@ -266,7 +292,11 @@ int gbfflush(gbfile *file) { if (file->gzapi) { +#if !ZLIB_INHIBITED return gzflush(file->handle.gz, Z_SYNC_FLUSH); +#else + abort(); +#endif } else { return fflush(file->handle.std); @@ -277,7 +307,9 @@ void gbfclearerr(gbfile *file) { if (file->gzapi) { +#if !ZLIB_INHIBITED gzclearerr(file->handle.gz); +#endif } else { clearerr(file->handle.std); @@ -290,7 +322,11 @@ gbferror(gbfile *file) int errnum; if (file->gzapi) { +#if !ZLIB_INHIBITED (void)gzerror(file->handle.gz, &errnum); +#else + abort(); +#endif } else { errnum = ferror(file->handle.std); @@ -313,7 +349,12 @@ gbfseek(gbfile *file, gbint32 offset, int whence) int result; assert(whence != SEEK_END); + +#if !ZLIB_INHIBITED result = gzseek(file->handle.gz, offset, whence); +#else + result = 1; +#endif is_fatal(result < 0, "%s: online compression not yet supported for this format!", file->module); return 0; @@ -328,7 +369,11 @@ gbsize_t gbftell(gbfile *file) { if (file->gzapi) { +#if !ZLIB_INHIBITED return gztell(file->handle.gz); +#else + abort(); +#endif } else { return ftell(file->handle.std); @@ -339,7 +384,11 @@ int gbfeof(gbfile *file) { if (file->gzapi) { +#if !ZLIB_INHIBITED return gzeof(file->handle.gz); +#else + abort(); +#endif } else { return feof(file->handle.std); @@ -350,7 +399,11 @@ int gbfungetc(const int c, gbfile *file) { if (file->gzapi) { +#if !ZLIB_INHIBITED return gzungetc(c, file->handle.gz); +#else + abort(); +#endif } else { return ungetc(c, file->handle.std); -- 2.30.2